<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "./../edit/index";
import Detail from "./../brand/index";
import Groups from "./../groups/index";
import Lable from "./../lable/index";
import Sort from "./../sort/index";
import Status from "./../Status/index";
import Report from "./../report/index";
export default {
    mixins: [
        Vue.prototype.$vFN.Mixins.Base,
        Vue.prototype.$vFN.Mixins.Page,
        Vue.prototype.$vFN.Mixins.Table,
    ],
    components: {
        ShareQrcodeBox: async () =>
            Vue.extend(
                await Vue.prototype.$vFN.Components.Base.ShareQrcodeBox()
            ),
    },
    computed: {
        styleProperty() {
            return this.$store.getters.get_styleProperty;
        },
    },
    data() {
        return {
            appWindow: window,
            searchSeniorLoading: 0,
            moreSearchShow: false,
            // 页面接口地址
            apiUrl: {
                list: "mall-site-portal/product/list",
                delete: "mall-site-portal/product/delete",
            },

            labelOptions: [],
            arrtOptions: [],
            brandOptions: [],
            serveOptions: [],
            groupsOptions: [],
            isIndeterminate: false,
            checkAll: false,

            groupsIds: [],
            // 列表高级查询参数
            mixinTable_tableSearchSenior: {
                // 商品分组一级ID
                groupsId: {
                    type: Number,
                    value: null,
                    default: null,
                },
                // 商品分组二级ID
                subGroupsId: {
                    type: Number,
                    value: null,
                    default: null,
                },
                minPrice: {
                    type: Number,
                    value: 0,
                    default: 0,
                },
                maxPrice: {
                    type: Number,
                    value: 1000000,
                    default: 1000000,
                },
                productTypeLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品标签
                labelIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品品牌
                brandIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品属性
                attributeValueIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品服务
                serveValueIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },

                putAwayTimeStartStr: {
                    type: String,
                    // '2020-02-02 09:09:09',
                    value: "",
                    default: "",
                },
                putAwayTimeEndStr: {
                    type: String,
                    // '2020-02-02 09:09:09',
                    value: "",
                    default: "",
                },
            },
            mixinTable_tableSearchConst:{
                isStbz:0,
            },
            mixinTable_tableSearchData: {
                name: "",
                publishStatus: "",
            },
            // 表格数据
            tableData: [],
            // 表格数据删除展示结构
            tableDeleteConfig: {
                columns: [
                    {
                        label: "封面图",
                        prop: "albumUrl",
                        type: "img",
                    },
                    {
                        label: "品牌名称",
                        prop: "name",
                    },
                    {
                        label: "价格",
                        prop: "salePrice",
                    },
                    {
                        label: "总库存",
                        prop: "stock",
                    },
                    {
                        label: "实际销量",
                        prop: "orderSales",
                    },
                ],
            },

            value: "",

            // 导出文件的数据
            exportData: {
                name: {
                    type: String,
                    value: "",
                    default: "",
                },
                publishStatus: {
                    type: Number,
                    value: null,
                    default: null,
                },

                // 商品分组一级ID
                groupsId: {
                    type: Number,
                    value: null,
                    default: null,
                },
                // 商品分组二级ID
                subGroupsId: {
                    type: Number,
                    value: null,
                    default: null,
                },
                minPrice: {
                    type: Number,
                    value: 0,
                    default: 0,
                },
                maxPrice: {
                    type: Number,
                    value: 1000000,
                    default: 1000000,
                },
                productTypeLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品标签
                labelIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品品牌
                brandIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品属性
                attributeValueIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },
                // 商品服务
                serveValueIdLst: {
                    type: Array,
                    value: null,
                    default: null,
                },

                putAwayTimeStartStr: {
                    type: String,
                    // '2020-02-02 09:09:09',
                    value: "",
                    default: "",
                },
                putAwayTimeEndStr: {
                    type: String,
                    // '2020-02-02 09:09:09',
                    value: "",
                    default: "",
                },
            },

            // 导出用到的分组id
            exportGroupsIds: [],
        };
    },
    methods: {
        showCode(_id) {
            this.$refs["shareQrcodeBox" + _id].init({
                config: {
                    path: "/packGoodsDetail/shop/index",
                    query: {
                        id: _id,
                    },
                },
            });
        },

        handleClick(value) {
            let _v = {
                index: value,
                product_id: this.mixinTable_selectTableData,
                onSuccess: (res) => {
                    this.mixinTable_refreshData();
                },
            };
            if (value == 1 && this.mixinTable_selectTableData.length != 0) {
                Detail.init(_v);
            } else if (
                value == 2 &&
                this.mixinTable_selectTableData.length != 0
            ) {
                Groups.init(_v);
            } else if (
                value == 3 &&
                this.mixinTable_selectTableData.length != 0
            ) {
                Lable.init(_v);
            } else if (
                value == 4 &&
                this.mixinTable_selectTableData.length != 0
            ) {
                Sort.init(_v);
            } else if (
                value == 5 &&
                this.mixinTable_selectTableData.length != 0
            ) {
                Status.init(_v);
            }
            console.log(this.mixinTable_selectTableData);
        },

        // 打开高级搜索
        async showSearchSeniorBox() {
            this.getLabelOptions();
            this.getGroupsOptions();
            this.getBrandOptions();
            this.getArrtOptions();
            this.getServeOptions();
        },
        // 数据源 标签
        async getLabelOptions() {
            if (this.labelOptions.length > 0) return;
            this.labelOptions = await this.$vFN.Tools.getSelectListSource(
                {
                    url: "mall-site-portal/product/listLabel",
                },
                window
            );

            this.searchSeniorLoading += 1;
        },
        // 数据源 分组
        async getGroupsOptions() {
            if (this.groupsOptions.length > 0) return;
            this.groupsOptions = await this.$vFN.Tools.getSelectListSource(
                {
                    url: "mall-site-portal/product/listGroups",
                },
                window
            );
            this.searchSeniorLoading += 1;
        },
        // 数据源 品牌
        async getBrandOptions() {
            if (this.brandOptions.length > 0) return;
            this.brandOptions = await this.$vFN.Tools.getSelectListSource(
                {
                    url: "mall-site-portal/product/listBrand",
                },
                window
            );
            this.searchSeniorLoading += 1;
        },
        // 数据源 属性
        async getArrtOptions() {
            if (this.arrtOptions.length > 0) return;
            this.arrtOptions = await this.$vFN.Tools.getSelectListSource(
                {
                    url: "mall-site-portal/product/listAttribute",
                },
                window
            );
            this.searchSeniorLoading += 1;
        },
        // 数据源 服务
        async getServeOptions() {
            if (this.serveOptions.length > 0) return;
            this.serveOptions = await this.$vFN.Tools.getSelectListSource(
                {
                    url: "mall-site-portal/product/listServe",
                },
                window
            );
            this.searchSeniorLoading += 1;
        },

        // 导出报表
        report() {
            Report.init({});
        },
        // async exportTable() {
        //   let dataObj_ = {};
        //   for (const key in this.exportData) {
        //     dataObj_[key] = this.exportData[key].value;
        //   }

        //   let res = await this.$vFN.Http.post(
        //     {
        //       url: "mall-site-portal/product/exportProductList",
        //       data: dataObj_,
        //     },
        //     window
        //   );

        //   if (res._ok) {
        //     this.$vFN.Tools.messageSuccess("操作成功，请到下载中心查看");
        //   }
        // },

        // // 清空导出筛选
        // clearExport() {
        //   for (const key in this.exportData) {
        //     this.exportData[key].value = this.exportData[key].default;
        //   }
        // },

        // 打开添加/修改
        editBoxOpen(params_) {
            Edit.init({
                mixinEdit_parent: this,
                mixinEdit_editType: params_.type,
                id: params_.id,
                onSuccess: (res) => {
                    this.mixinTable_refreshData();
                },
            });
        },
        // 初始化
        async init() {
            this.labelOptions = [];
            this.groupsOptions = [];
            this.brandOptions = [];
            this.arrtOptions = [];
            this.serveOptions = [];
            this.searchSeniorLoading = 0;
            // 刷新表格数据，此方法扩展时可重写
            this.mixinTable_refreshData();
        },
    },
    watch: {
        // 监控选择的分组数据，如果有更改则赋值给 mixinTable_tableSearchSenior 里供查询条件
        groupsIds: {
            handler(newVal, oldVal) {
                if (newVal.length > 0) {
                    if (oldVal != null) {
                        if (newVal.join(",") == oldVal.join(",")) {
                            return;
                        }
                    }
                    this.mixinTable_tableSearchSenior.groupsId.value =
                        newVal[0];
                    this.mixinTable_tableSearchSenior.subGroupsId.value =
                        newVal[1];
                } else {
                    this.mixinTable_tableSearchSenior.groupsId.value = null;
                    this.mixinTable_tableSearchSenior.subGroupsId.value = null;
                }
            },
            immediate: true,
            deep: true,
        },
        // 监控 mixinTable_tableSearchSenior 里供查询条件如果有更改反馈给 groupsIds 供页面回显
        "mixinTable_tableSearchSenior.groupsId.value": {
            handler(newVal, oldVal) {
                if (newVal != oldVal) {
                    if (newVal) {
                        this.groupsIds[0] = newVal + "";
                    } else {
                        this.groupsIds = [];
                    }
                }
            },
            immediate: true,
            deep: true,
        },
        "mixinTable_tableSearchSenior.subGroupsId.value": {
            handler(newVal, oldVal) {
                if (newVal != oldVal) {
                    if (newVal) {
                        this.groupsIds[1] = newVal + "";
                    } else {
                        this.groupsIds = [];
                    }
                }
            },
            immediate: true,
            deep: true,
        },
        exportGroupsIds: {
            handler(newVal, oldVal) {
                if (newVal.length > 0) {
                    if (oldVal != null) {
                        if (newVal.join(",") == oldVal.join(",")) {
                            return;
                        }
                    }
                    this.exportData.groupsId.value = newVal[0];
                    this.exportData.subGroupsId.value = newVal[1];
                } else {
                    this.exportData.groupsId.value = null;
                    this.exportData.subGroupsId.value = null;
                }
            },
            immediate: true,
            deep: true,
        },
        "exportData.groupsId.value": {
            handler(newVal, oldVal) {
                if (newVal != oldVal) {
                    if (newVal) {
                        this.exportGroupsIds[0] = newVal + "";
                    } else {
                        this.exportGroupsIds = [];
                    }
                }
            },
            immediate: true,
            deep: true,
        },
        "exportData.subGroupsId.value": {
            handler(newVal, oldVal) {
                if (newVal != oldVal) {
                    if (newVal) {
                        this.exportGroupsIds[1] = newVal + "";
                    } else {
                        this.exportGroupsIds = [];
                    }
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {
        this.init();
    },
    activated() {},
};
</script>
